<!-- src/views/video_table.vue -->
<template>
  <div class="container mt-5">
    <h2>视频源信息表</h2>

    <!-- 加载提示 -->
    <div v-if="loading" class="alert alert-info">加载中...</div>

    <!-- 错误提示 -->
    <div v-if="error" class="alert alert-danger">{{ error }}</div>

    <!-- 表格展示 -->
    <table v-if="!loading && !error" class="table table-striped table-bordered">
      <thead class="thead-dark">
        <tr>
          <th>序号</th>
          <th>视频标题</th>
          <th>发布时间</th>
          <th>品牌</th>
          <th>字幕内容</th>
          <th>评论量</th>
          <th>观看量</th>
          <th>录入时间</th>
          <th>字幕处理时间</th>
          <th>评论处理状态</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(video, index) in videos" :key="video.id">
          <td>{{ index + 1 }}</td>
          <td>{{ video.video_title }}</td>
          <td>{{ video.published_at }}</td>
          <td>{{ video.brand }}</td>
          <td>{{ video.subtitle_content }}</td>
          <td>{{ video.comment_count }}</td>
          <td>{{ video.view_count }}</td>
          <td>{{ video.entered_time }}</td>
          <td>{{ video.subtitle_processed_time }}</td>
          <td>{{ video.comment_process_status }}</td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      videos: [],
      loading: true,
      error: null
    };
  },
  mounted() {
    fetch('/api/videos')
      .then(res => res.json())
      .then(data => {
        this.videos = data;
        this.loading = false;
      })
      .catch(err => {
        console.error('❌ 接口请求失败:', err);
        this.error = '加载失败，请检查后端是否运行';
        this.loading = false;
      });
  }
};
</script>

<style scoped>
.container {
  max-width: 1200px;
}
.table {
  width: 100%;
}
.alert {
  margin-top: 1rem;
}
</style>